﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using DynaSpace.Menu;

namespace DynaSpace
{
	/// <summary>
	/// Plugin zajišťující vykreslování loga DynaSpace
	/// </summary>
	internal class LogoComponent : DynaComponentBase
	{
		private Texture2D logo; // logo DynaSpace
		private double secondsToHide = 3; // za jak dlouho se logo schová
		private byte alpha;

		public LogoComponent(DynaGame game)
			: base(game)
		{
		}

		protected override void LoadContent()
		{
			base.LoadContent();

			logo = Game.Content.Load<Texture2D>("Core\\Gfx\\logo_dynaspace_full");

			DrawOrder = 100;
		}

		public override void Update(GameTime gameTime)
		{
			base.Update(gameTime);

			// ponížit alpha hodnotu a čas do skrytí
			secondsToHide -= gameTime.ElapsedGameTime.TotalSeconds;
			alpha = (byte)(Math.Max(0, Math.Min(1, secondsToHide)) * 255);
	
			if (secondsToHide < 0)
			{
				// logo je schované
				this.Enabled = false;
				alpha = 0;
				secondsToHide = 0;
				logo.Dispose();
			}
		}

		public override void Draw(GameTime gameTime)
		{
			base.Draw(gameTime);
			
			if (alpha > 0)
			{
				GraphicsDevice.Viewport = Game.DefaultViewport;
				spriteBatch.Begin();
				spriteBatch.Draw(logo, Game.CenterTexture(logo), new Color(Color.White, alpha));
				spriteBatch.End();
			}
		}

	}
}
